<?php 
function task_display($_this) {
	require_once(APPPATH.'libraries/google-api-php-client/src/Google_Client.php');
	require_once(APPPATH.'libraries/google-api-php-client/src/contrib/Google_TasksService.php');

	$client= new Google_client();

	$tasksService = new Google_TasksService($client);
	if ($_this->session->userdata('token')) {
		$html = "";

		$client->setAccessToken($_this->session->userdata('token'));
		$lists = $tasksService->tasklists->listTasklists();
		$html .= "<ul class='nav nav-list'>\n";
		foreach ($lists['items'] as $list) {

			$task = new Google_Task();
			$task->setTitle("New Task");
			$task->setNotes("Please complete me");

				//$result =  $tasksService->tasks->insert($list['id'], $task);

			$html = $html." <li class='nav-header'>{$list['title']}</li> \n";
			$tasks = $tasksService->tasks->listTasks($list['id']);
			if(isset($tasks['items']) && count($tasks['items']) > 0){
					//$html.="<ul>";

				foreach($tasks['items'] as $task){
					$html.= "<li><a href='#'>".$task['title']."</a></li>";
				}

					//$html .="</ul>";
			}
		}
		$html .= "</ul>\n";
	} else {
		$html = "No access token";
	}

	return $html;
}

